package com.xiaomili.halfsugar.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.xiaomili.halfsugar.R;

import java.io.File;
import java.util.List;

/**
 * Created by Administrator on 2016/7/15 0015.
 */
public class MyAdapter extends BaseAdapter{
    private Context mContext;
    private List<String> mDatas;

    public MyAdapter(Context mContext, List<String> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
    }

    @Override
    public int getCount() {
        Log.i("ss","size-->"+mDatas.size());
        return mDatas==null?0:mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.item_grid, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        //String url = mDatas.get(position);
        Picasso.with(mContext).load(new File(mDatas.get(position)))
                .config(Bitmap.Config.RGB_565)
                .resize(200, 200)
                .centerInside()
                .into(holder.iv_grid);
        return convertView;
    }
    class ViewHolder{

        private ImageView iv_grid;
        public ViewHolder(View itemView) {
            iv_grid = (ImageView) itemView.findViewById(R.id.iv_grid);
        }
    }
}
